/**
 * @Author quan
 * @Description 实现前后端的交互
 * @Date 2023/6/29 9:29
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

/**
 * 获取所有的表白信息
 */
@WebServlet("/getAllMessage")
public class getMessageServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、定义编码格式
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json;charset=utf-8");
        //2、获取所有的表白数据，转化为json格式
//        String jsonStr = AppVar.OBJECT_MAPPER.writeValueAsString(AppVar.MESSAGE_LIST);//jsonStr相当于只有下面的data
        //放在map中返回
        HashMap<String,Object> map = new HashMap<String, Object>();
        map.put("code",200);
        map.put("msg","");
        map.put("data",AppVar.MESSAGE_LIST);
        //3、将结果返回
        String jsonStr = AppVar.OBJECT_MAPPER.writeValueAsString(map);
        resp.getWriter().write(jsonStr);
    }
}
